import times from 'lodash/times';

interface Options {
  min: number;
  max: number;
}
// generate random word list
export function generateList(count: number, options: Options = { min: 5, max: 10 }) {
  const { min, max } = options;
  return times(count, () => {
    const length = Math.random() * (max - min) + min;
    return generateWord(length);
  });
}

// generate random word
export function generateWord(length: number) {
  return times(length, () => generateLetter()).join('');
}

// generate random letter
export function generateLetter() {
  // lower case ASCII value
  const START_INDEX: number = 97;
  // letter count
  const LETTER_COUNT: number = 26;
  const randomValue: number = START_INDEX + Math.random() * LETTER_COUNT;
  const randomCode: string = String.fromCharCode(Math.floor(randomValue));
  return randomCode;
}
